package io.renren.modules.medical.controller;

import io.renren.common.result.Result;
import io.renren.common.utils.PageUtils;
import io.renren.modules.medical.service.OnlineChatService;
import io.renren.modules.medical.vo.weixinVo.ApiChatHistory;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * 在线咨询接口
 * @author Luo Sheng
 * @school YiBin university
 * @create 2023-04-18 15:17
 */
@RequiredArgsConstructor
@RequestMapping("/medical/chat")
@RestController
public class OnlineChatController {

    private final OnlineChatService onlineChatService;

    /**
     * 诊断时获取到医生下的病人 发送时传输
     */
    @RequiresPermissions("onlineinterflow:send")
    @GetMapping("/patient/list")
    public Result<PageUtils> page(@RequestParam Map<String, Object> params){
        PageUtils page = onlineChatService.queryPageByUserId(params);
        return Result.success(page);
    }

    /**
     * 获得聊天历史
     */
    @RequiresPermissions("onlineinterflow:history")
    @GetMapping("/history")
    public Result<List<ApiChatHistory>> history(@RequestParam Map<String, Object> params){
        List<ApiChatHistory> chatListVoList = onlineChatService.historyToMedical(params);
        return Result.success(chatListVoList);
    }

    /**
     * 清空历史未读
     */
    @GetMapping("/clear/{sendId}/{sendToId}")
    public Result<String> clear(@PathVariable("sendId") Long sendId,
                                @PathVariable("sendToId") Long sendToId){
        onlineChatService.clearNoneVisit(sendId, sendToId);
        return Result.success(null);
    }
}
